package com.titan.demo.camel.sample.eip.split;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;

import com.titan.demo.camel.utils.RunCamel;

public class SplitArrayTest {
	public static void main(String[] args) {
        try {
        	RouteBuilder route = createRouteBuilder();
        	createRunCamel().run(route);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	
	private static RunCamel createRunCamel() {
		return new RunCamel() {
			protected void execute(CamelContext context,
					ProducerTemplate producer, ConsumerTemplate consumer)
					throws Exception {
				String[] data = new String[5];
				for (int i = 0; i < 5; i++) {
					data[i] = "值【"+i+"】";
				}
				producer.sendBody("direct:in", data);
			}
		};
	}
	
	private static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:in")
                .split(body())
                .process(new Processor() {
					public void process(Exchange exchange) throws Exception {
						System.out.println("环境信息： size=["+exchange.getProperty("CamelSplitSize")+"]  index=["+exchange.getProperty("CamelSplitIndex")+"]  isComplete=["+exchange.getProperty("CamelSplitComplete")+"]");
						System.out.println("循环数据："+exchange.getIn().getBody());
					}
                })
                ;
            }
        };
    }
}
